package com.rover022.flixelgame.element.weapon
{
	import com.greensock.TweenMax;
	import com.greensock.easing.Linear;
	import com.rover022.flixelgame.element.BaseElement;
	import com.rover022.flixelgame.element.weapon.bullet.BowBullet;
	import org.flixel.FlxG;
	import org.flixel.FlxPoint;

	/**
	 * 弓  从玩家坐标点拉出一个曲线射向敌人
	 * @author flashpig
	 *
	 */
	public class Bow extends BaseFlxWeapon
	{
		public var shootTime:Number = 1;
		public var shootHeight:Number = 40;

		public function Bow(name:String, parentRef:* = null, xVariable:String = "x", yVariable:String = "y")
		{
			super(name, parentRef, xVariable, yVariable);
		}

		override public function fireAtElement(target:BaseElement):Boolean
		{
			//计算武器拥有者 和 目标之间的距离
			var bronP:FlxPoint = parent.getMidpoint();
			var killP:FlxPoint = target.getMidpoint();
			var _midx:Number = (bronP.x + killP.x) / 2;
			var _midy:Number = (bronP.y + killP.y) / 2;
			var bornPoint:FlxPoint = new FlxPoint(_midx, _midy - shootHeight);
			var bullet:BowBullet = new BowBullet(this, 0);
			bullet.x = bronP.x;
			bullet.y = bronP.y;
			TweenMax.to(bullet, FlxG.timeScale * shootTime, {bezierThrough: [{x: bronP.x, y: bronP.y}, {x: killP.x, y: killP.y}], orientToBezier: true, ease: Linear.easeNone});
			return true;
		}
	}
}
